home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CALayout.cpp
-
- Contains: Layout & imaging code for CALib
-
- Written by: Rick Badertscher, Jens Alfke, Greg Ames, David Nelson
-
- Copyright: © 1994 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
-
- <15> 11/21/95 RB Made all acquire operations use temp objects
- <14> 8/2/95 RB Removed CAGetEmbeddedFrameRef(), Moved CAGetRootFrame()
- and CARemoveFrameRef() to CADataX.cpp
- <13> 5/15/95 RB Adding CAInstallFrameAddedHandler(),
- CAInstallFrameAddedHandler(), and
- CAInstallEventInEmbeddedHandler(),
- <12> 5/12/95 RB Fixing bug in CAGetEmbeddedFrame()
- Moving all visFrame stuff to CADisplay.cpp
- <11> 4/22/95 RB Added CARemoveVisFrame()
- <10> 4/19/95 RB API Renovation. Transform support.
- <9> 4/07/95 RB Corrected some ref counting errors.
- <8> 3/30/95 RB Integrating changes for b1c14 build
- <7> 3/30/95 RB Mods to CAOffsetFrame().
- Added method CAGetEmbeddedFrameRef(). Frame iterator.
- <6> 3/25/95 RB Implemented CAGetUsedRgn(), CAGetFrameRgn(), CASetFrameRgn(),
- and CAGetVisFrame().
- <5> 3/15/95 RB Added routine CAOffsetFrame(), for scrolling.
- <4+> 2/28/95 SJF Add debug stuff to API calls
- <4> 2/13/95 SJF Interim checkin to update project database
- <3) 12/15/94 SJF change somGetGlobalEnvironment to _gpProxyShell->GetGlobalEnvironment
- <2> 12/15/94 SJF Move NewShape method to CACommon.cpp
- <1> 10/30/94 GCA,DHN All mods to make project compile with no
- errors under OpenDoc b1 (with SOM).
- <0> 10/30/94 SV SOMverted
-
- To Do:
- */
-
- #ifndef _CASESSN_
- #include "CASessn.h"
- #endif
-
- #ifndef _CAERROR_
- #include "CAError.h"
- #endif
-
- #ifndef _CAFRMUTL_
- #include "CAFrmUtl.h"
- #endif
-
- #ifndef _CAUTIL_
- #include "CAUtil.h"
- #endif
-
- #ifndef _CADOCPRIV_
- #include "CADocPriv.h"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _CAPROXYPARTDEF_
- #include "CAProxyPartDef.h"
- #endif
-
- #ifndef CAProxyExtension_API
- #include "CAProxyExtension.xh"
- #endif
-
- #ifndef _CADEBUG_
- #include "CADebug.h"
- #endif
-
- #ifndef SOM_ODFoci_xh
- #include <Foci.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef SOM_ODFrameFacetIterator_xh
- #include <FrFaItr.xh>
- #endif
-
-
- #pragma segment CALib
-
-
-
- //-------------------------------------------------------------------------
- // Variables
- //-------------------------------------------------------------------------
-
-
- //-------------------------------------------------------------------------
- // Layout
- //-------------------------------------------------------------------------
-
- //-------------------------------------------------------------------------
-
- pascal RgnHandle
- CAGetFrameRgn( CADocumentRef document, CAFrameRef frame )
- {
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_DOCREF ("CAGetFrameRgn", document);
- VALIDATE_FRAMEREF ("CAGetFrameRgn", document, frame);
- #endif
-
- Environment* ev = gCASession->GetEV();
- ODRgnHandle rgn = kODNULL;
-
- if (FailIfNotVisible(document)) return NULL;
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frame);
- TempODShape tempShape = tempFrame->AcquireFrameShape (ev, kODNULL);
- rgn = tempShape->CopyQDRegion (ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return rgn;
-
- // Caller is responsible for usedRgn memory
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal void
- CASetFrameRgn( CADocumentRef document, CAFrameRef frame,
- RgnHandle frameRgn )
- {
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_DOCREF ("CASetFrameRgn", document);
- VALIDATE_FRAMEREF ("CASetFrameRgn", document, frame);
- #endif
-
- Environment* ev = gCASession->GetEV();
-
- if (FailIfNotVisible(document)) return;
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef (document,frame);
- tempFrame->Invalidate (ev, kODNULL, kODNULL);
-
- TempODShape tempShape = tempFrame->CreateShape (ev);
- tempShape->SetQDRegion (ev, frameRgn);
- tempFrame->ChangeFrameShape(ev, tempShape, kODNULL); // GCA HACK added kODNULL (ODCanvas) 10/30/94
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
-
-
- //-------------------------------------------------------------------------
-
- pascal RgnHandle
- CAGetUsedRgn( CADocumentRef document, CAFrameRef frame )
- {
-
- #ifdef RUNTIME_DEBUG
- VALIDATE_DOCREF ("CAGetUsedRgn", document);
- VALIDATE_FRAMEREF ("CAGetUsedRgn", document, frame);
- #endif
-
- Environment* ev = gCASession->GetEV();
- RgnHandle usedRgn = kODNULL;
-
- if (FailIfNotVisible(document)) return NULL;
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frame);
-
- if (tempFrame->IsRoot (ev))
- {
- ODPoint point;
- Point contentExtent, contentTransformPoint;
- ODFacet* facet;
-
- TempODWindow tempWindow = tempFrame->AcquireWindow(ev);
- facet = tempWindow->GetRootFacet(ev);
-
- tempFrame->GetContentExtent (ev, &point);
- contentExtent = point.AsQDPoint();
-
- TempODTransform tempTransform = facet->AcquireContentTransform (ev, kODNULL);
- contentTransformPoint = tempTransform->GetQDOffset (ev);
- }
-
- TempODShape tempUsedShape = tempFrame->AcquireUsedShape (ev, kODNULL);
- usedRgn = tempUsedShape->CopyQDRegion (ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (usedRgn);
-
- // Caller is responsible for usedRgn memory
-
- }
-
-
-
- //-------------------------------------------------------------------------
-
- pascal Boolean
- CAGetFrozen( CADocumentRef document, CAFrameRef frame )
- {
-
- Environment* ev = gCASession->GetEV();
- Boolean retVal = kODFalse;
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef(document, frame);
- retVal = tempFrame->IsFrozen(ev);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (retVal);
-
- }
-
-
- //-------------------------------------------------------------------------
-
- pascal void
- CASetFrozen( CADocumentRef document, CAFrameRef frame, Boolean isFrozen )
- {
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef(document, frame);
- tempFrame->SetFrozen(ev, isFrozen);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal void CAGetFrameTransform ( CADocumentRef document,
- CAFrameRef frameRef,
- CATransform* transform)
- {
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frameRef);
-
- // Get the internal transform of the frame
-
- TempODTransform tempTransform = tempFrame->AcquireInternalTransform (ev, kODNULL);
- THROW_IF_NULL (tempTransform);
- tempTransform->GetMatrix(ev, (ODMatrix*) transform);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal void CASetFrameTransform( CADocumentRef document,
- CAFrameRef frameRef,
- CATransform* transform)
- {
-
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frameRef);
- THROW_IF_NULL (tempFrame);
-
- // By default the external transform is identity
- TempODTransform tempTransform = tempFrame->CreateTransform(ev);
- THROW_IF_NULL (tempTransform);
-
- tempTransform->SetMatrix (ev, (ODMatrix*) transform);
- tempFrame->ChangeInternalTransform (ev, tempTransform, kODNULL);
-
- //tempFrame->Invalidate (ev, kODNULL, kODNULL);
-
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return;
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal Boolean CAShowPartFrameInfo(CADocumentRef document, CAVisFrame visFrame)
- {
-
- Environment* ev = gCASession->GetEV();
- ODInfo* info;
- ODDraft* draft = kODNULL;
- ODDraftPermissions perms;
-
-
- CA_TRY
-
- info = gCASession->GetODSession()->GetInfo(ev);
- THROW_IF_NULL (info);
-
- draft = ((CADocument*)document)->GetDraft();
- perms = draft->GetPermissions(ev);
-
- info->ShowPartFrameInfo( ev, (ODFacet*)visFrame, perms >= kODDPSharedWrite);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (true);
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal void CAViewFrameInWindow (CADocumentRef document, CAFrameRef frame)
- {
-
- Environment* ev = gCASession->GetEV();
-
- CA_TRY
-
- TempODFrame tempFrame = AcquireFrameFromFrameRef (document, frame);
- TempODPart tempPart = tempFrame->AcquirePart (ev);
- tempPart->Open(ev, tempFrame);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- }
-
- //-------------------------------------------------------------------------
-
- pascal Boolean CAActiveBorderContainsPoint (Point mouse)
- {
-
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODArbitrator* arbitrator = gCASession->GetArbitrator();
- Boolean cursorInActiveBorder = false;
- ODFacet* rootFacet;
- ODPoint odPoint;
- ODPoint windowMouse;
-
- odPoint = mouse;
-
- CA_TRY
-
- TempODWindow tempWindow = windowState->AcquireActiveWindow (ev);
-
- if (tempWindow)
- {
- // Get the root facet
- rootFacet = tempWindow->GetRootFacet (ev);
-
- // get the active frame
- TempODFrame tempFrame = arbitrator->AcquireFocusOwner(ev, gCASession->GetODSession()->Tokenize(ev, kODSelectionFocus));
-
- if (tempFrame && !tempFrame->IsRoot(ev))
- {
-
- ODFrameFacetIterator* iter = tempFrame->CreateFacetIterator(ev);
- ODPoint windowPoint;
-
- TempODTransform windowFrameXForm = rootFacet->AcquireWindowFrameTransform(ev, kODNULL);
- windowPoint = odPoint;
- windowFrameXForm->TransformPoint(ev, &windowPoint);
-
- // For each facet, check if the active border contains the mouse
- for (ODFacet* facet = iter->First(ev); iter->IsNotComplete(ev);
- facet = iter->Next(ev))
- {
- TempODTransform xForm = facet->AcquireWindowFrameTransform(ev, kODNULL);
- ODPoint framePoint;
-
- framePoint = windowPoint;
- xForm->InvertPoint(ev, &framePoint);
-
- if (facet->ActiveBorderContainsPoint(ev, &framePoint, kODNULL))
- {
- cursorInActiveBorder = true;
- break;
- }
- }
- ODDeleteObject(iter);
- }
- }
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- return (cursorInActiveBorder);
-
- }
-
-
-
- //-------------------------------------------------------------------------
- pascal void CAInstallFrameShapeRequestHandler ( CAFrameShapeRequestHandler handler,
- CADocumentRef document)
- {
- Environment* ev = gCASession->GetEV();
- ODPart* rootPart = kODNULL;
- CAProxyExtension* proxyExt = kODNULL;
-
-
- CA_TRY
-
- rootPart = ((CADocument*)document)->AcquireRootPart();
- proxyExt = (CAProxyExtension*)rootPart->AcquireExtension( ev, kCAProxyPartExtension );
-
- THROW_IF_NULL (proxyExt);
-
- proxyExt->InstallCAFrameShapeRequestHandler( ev,
- (CAProxyHookFrameShapeRequest) ProxyHook_FrameShapeRequest, handler);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODReleaseObject (ev, proxyExt);
- ODReleaseObject (ev, rootPart);
-
- }
-
- //-------------------------------------------------------------------------
-
-
- pascal void CAInstallBorderAdjuster(CADocumentRef document,
- CAAdjustBorderProc theProc)
- {
- Environment* ev = gCASession->GetEV();
- ODWindowState* windowState = gCASession->GetODSession()->GetWindowState(ev);
- ODPart* rootPart = kODNULL;
- CAProxyExtension* proxyExt = kODNULL;
-
-
- CA_TRY
-
- rootPart = ((CADocument*)document)->AcquireRootPart();
- proxyExt = (CAProxyExtension*)rootPart->AcquireExtension( ev, kCAProxyPartExtension );
-
- THROW_IF_NULL (proxyExt);
-
- proxyExt->InstallCAAdjustBorderHandler( ev,
- (CAProxyHookAdjustBorder) ProxyHook_AdjustBorder, theProc);
-
- CA_CATCH_ALL
- CA_ENDTRY
-
- ODReleaseObject (ev, proxyExt);
- ODReleaseObject (ev, rootPart);
-
- }